package institutional

import inscription.InscriptionCourse;
import user.Professor;
import util.Day

class Course {
	def inscriptionService
	
	boolean available //el curso puede no estar habilitado
	int size // cantidad de alumnos permitidos
	Date dateOfCreation
	String timetable
	
	static belongsTo = [subject: Subject, professor: Professor]
	
    static constraints = {
		subject()
		professor()
		size(nullable: false) 
		timetable(nullable: false, blank: false)
		available()
		dateOfCreation display: false
    }
	
	String toString () {
		String s = subject.toString() + " - " + professor.toString();
		return s
	}
	
	int getRemainingSpots(){
		int inscriptionCount = InscriptionCourse
		.findAll("from InscriptionCourse ic where ic.semester=:semester and ic.course=:course",
			[semester: inscriptionService.getCurrentSemester(), course: this]).size()
			
		return size - inscriptionCount
	}
	
	
}
